package com.common.model;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.builder.ToStringBuilder;

public class ContentPagination {
	private String contentString = "";
	private int contentLength = 0;
	private int pageSizeCount = 0;
	private int perPageLength = 10;
	private int currentPage = 1;
	private Map<String, StringBuffer> subcontent = null;

	public void setSubcontent(String content) {

		this.contentString = content;
		this.contentLength = contentString.split("<br/>").length;
		this.pageSizeCount = (int) Math.ceil((double) contentLength
				/ perPageLength);

		Map<String, StringBuffer> map = new HashMap<String, StringBuffer>();
		for (int i = 0; i < pageSizeCount; i++) {
			if (i < (pageSizeCount - 1)) {
				StringBuffer str = new StringBuffer();
				for (int j = i * perPageLength; j < perPageLength * (i + 1); j++) {
					str.append(contentString.split("<br/>")[j]);
					System.out.println("subcontent" + str);
				}
				map.put("subcontent" + (i + 1), str);
			} else {
				StringBuffer str = new StringBuffer();
				for (int j = i * perPageLength; j < contentLength; j++) {
					str.append(contentString.split("<br/>")[j]);
					System.out.println("subcontent" + str);
				}
				map.put("subcontent" + (i + 1), str);
			}

		}
		this.subcontent = map;

	}

	public String getContentString() {
		return contentString;
	}

	public void setContentString(String contentString) {
		this.contentString = contentString;
	}

	public int getContentLength() {
		return contentLength;
	}

	public void setContentLength(int contentLength) {
		this.contentLength = contentLength;
	}

	public int getPageSizeCount() {
		return pageSizeCount;
	}

	public void setPageSizeCount(int pageSizeCount) {
		this.pageSizeCount = pageSizeCount;
	}

	public int getPerPageLength() {
		return perPageLength;
	}

	public void setPerPageLength(int perPageLength) {
		this.perPageLength = perPageLength;
	}

	public Map<String, StringBuffer> getSubcontent() {
		return subcontent;
	}

	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

}
